#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
const int N = 60;
char a[N][N];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				cin >> a[i][j];
		
		for (int j = 1; j <= m; j++)
		{
			for (int i = n; i >= 1; i--)
			{
				if (a[i][j] == '.')
				{
					for (int k = i - 1; k >= 0; k--)
					{
						if (a[k][j] == '*')
						{
							char tmp = a[k][j];
							a[k][j] = a[i][j];
							a[i][j] = tmp;
						}
						else if (a[k][j] == '#')
							break;
					}
				}
			}
		}
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
				cout << a[i][j];
			cout << endl;
		}
	}
	return 0;
}